package com.aoxon.cargo.shared;

import java.util.ArrayList;
import java.util.List;

import com.aoxon.cargo.bean.Cloth;
import com.google.gson.reflect.TypeToken;

/**
 * 物品收藏本地数据的保存
 * @author ZZJ
 *
 */
public class CollectGoodsShared extends MyShared {

	/**
	 * 获取物品收藏记录列表数据
	 */
	public static List<Cloth> getColGoodsList() {
		List<Cloth> cloths = new ArrayList<Cloth>();
		String strCollection = sp.getString("GoodsCollection", "");
		if (!strCollection.equals("")) {
			cloths = gson.fromJson(strCollection, new TypeToken<ArrayList<Cloth>>() {
			}.getType());
		}
		return cloths;
	}

	/**
	 * 保存物品收藏记录列表数据
	 * @param cloths
	 */
	public static void saveColGoodsList(List<Cloth> cloths) {
		saveDate("GoodsCollection", gson.toJson(cloths));
	}

	/**
	 * 保存单个物品收藏记录数据
	 * @param cloth
	 */
	public static void saveColGoods(Cloth cloth) {
		List<Cloth> cloths = getColGoodsList();
		cloths.add(cloth);
		saveDate("GoodsCollection", gson.toJson(cloths));
	}
}
